<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width,initial-scale=0.5,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no">
	<title>Document</title>
	<link rel="stylesheet" href="dist/normalize.css">
	<link rel="stylesheet" href="dist/style.css">
	<script src="https://cdn.bootcss.com/stylus/0.32.1/stylus.min.js"></script>
	<script src="dist/rem.js"></script>
</head>
<body>
	<header>访客登记表</header>
	<main>
		<form action="" method="post">
			<p><label>访客姓名:</label><input type="text" placeholder="必填" required="true" class="vname" name="vname" autofocus><span>*</span></p>
		    <p><label>访客手机号:</label><input type="number" placeholder="必填" required="true" maxlength="11" class="vtel" name="vtel"><span>*</span></p>
		    <p><label>来访原因:</label><input type="text" placeholder="必填" required="true" class="vreason" name="vreason"><span>*</span></p>
		    <p><label>联系人姓名:</label><input type="text" placeholder="必填" class="cname" name="cname"></p>
		    <p><label>联系人电话:</label><input type="number" placeholder="必填" required="true" maxlength="11" class="ctel" name="cname"><span>*</span></p>
		    <p>
			<label>选择来访孵化器:</label><select name="incubator" id="incubator">
				<option value="北京-融科">北京-融科</option>
				<option value="北京-鼎好">北京-鼎好</option>
				<option value="上海">上海</option>
			</select>
		    </p> 
		    <a class="submit" href="javascript:void(0);">提交申请</a>
		</form>
		
	</main>
    
    <script src="dist/zepto.min.js"></script>
    <script>
    	$(function(){
    		$(".submit").click(function(){
    		    let svname = $(".vname").val()
    		    let nvtel = $(".vtel").val()
    		    let svreason = $(".vreason").val()
    		    let scname = $(".cname").val()
    		    let nctel = $(".ctel").val()
    		    let sincubator = $("#incubator").val()
                let regextel = /^[1][3|4|5|7|8][0-9]{9}$/


    		    if(svname.trim().length == 0){
    			    alert("请填写访客姓名");
    			    return false
    		    }
    		    if(nvtel.trim().length == 0){
    			    alert("请输入你的手机号");
    			    return false
    		    }
                if(regextel.test(nvtel) || regextel.text(nctel)){
                    alert("您输入的手机号格式不正确");
                    return false
                }
                if(svreason.trim().length == 0){
                	alert("请输入来访原因");
                	return false
                }
                if(nctel.trim().length == 0){
                	alert("请输入联系人电话");
                	return false
                }

                $.ajax({
                	type:'POST',
                	dataType:'json',
                	url:'',
                    data: $("form").serialize(),
                    success:function(result){
                    	if(result.resultCode > 0){
                            alert('提交成功')
                    	}
                    },
                    error:function(){
                    	alert("异常")
                    }
                })
    	    })
    	})
    	
    </script>
</body>
</html>